package com.sqtracker.recommender.repository;

import com.sqtracker.recommender.model.RecommendationLog;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface RecommendationLogRepository extends MongoRepository<RecommendationLog, String> {

    List<RecommendationLog> findByUserId(String userId);

    List<RecommendationLog> findByUserIdOrderByContext_TimestampDesc(String userId);

    @Query(value = "{ 'userId': ?0 }", count = true)
    long countByUserId(String userId);

    List<RecommendationLog> findByContext_TimestampBetween(Date start, Date end);

    @Query("{ 'userId': ?0, 'recommendations.torrentId': ?1 }")
    List<RecommendationLog> findByUserIdAndRecommendedTorrentId(String userId, String torrentId);

    @Query("{ 'feedback.clicked': ?0 }")
    List<RecommendationLog> findByClickedTorrentId(String torrentId);
}